#include <QTimer>
#include <qdatetime.h>
#include <QDebug>

#include "formsysteminfo.h"
#include "ui_formsysteminfo.h"
#include "sysinfo.h"

FormSystemInfo::FormSystemInfo(QWidget *parent) :
        QWidget(parent),
        ui(new Ui::FormSystemInfo)
{
    ui->setupUi(this);
    setWindowFlags(windowFlags() | Qt::Dialog);
    setWindowModality(Qt::ApplicationModal);
    setAttribute(Qt::WA_DeleteOnClose);

    QDateTime time = QDateTime::currentDateTime();
    QString str = time.toString("yyyy-MM-dd hh:mm:ss");
    ui->labelSysTimeString->setText(str);
    ui->labelUploadwayString->setText(Sysinfo::getUploadway());
    ui->labelLocationString->setText(Sysinfo::getLocation());
    ui->labelVersionString->setText(Sysinfo::getVersion());
    ui->labelIPaddrString->setText(Sysinfo::getIpAddr(Sysinfo::getUploadIface()));


    systimer = new QTimer(this);
    connect(systimer, &QTimer::timeout, this, &FormSystemInfo::on_timerUpdate);

    systimer->start(1000);

    qDebug() << "[FormSystemInfo] \t Constructor";
}

FormSystemInfo::~FormSystemInfo()
{
    delete systimer;
    delete ui;

    qDebug() << "[FormSystemInfo] \t Destructor";
}

void FormSystemInfo::on_timerUpdate()
{
    QDateTime time = QDateTime::currentDateTime();
    QString str = time.toString("yyyy-MM-dd hh:mm:ss");
    ui->labelSysTimeString->setText(str);
    ui->labelUploadwayString->setText(Sysinfo::getUploadway());
    ui->labelLocationString->setText(Sysinfo::getLocation());
    ui->labelVersionString->setText(Sysinfo::getVersion());
    ui->labelIPaddrString->setText(Sysinfo::getIpAddr(Sysinfo::getUploadIface()));
//    ui->verticalSliderBackLight->setValue(sysinfo.getBackLight());
}

void FormSystemInfo::on_pushButtonReturn_clicked()
{
    this->close();
}
